<template>
  <div>
    <vxe_table
      ref="baseTable"
      :options="options"
      @handleTableBtn="handleTableBtn"
    >
    </vxe_table>
    <!-- 评估 -->
    <evaluate ref="evaluateDialog" @success="success"></evaluate>
    <!-- 发货 -->
    <Fahuo ref="Fahuo" @success="success"></Fahuo>
    <!-- 详情 -->
     <info ref="info"></info>
  </div>
</template>

<script>
import { list, upAndDwon, del, importLight, receiveAck } from "@/api/es";
import vxe_table from "@/components/table/vxe_table.vue";
import tableMixin from "@/mixins";
import evaluate from "./evaluate.vue";
import info from "./info.vue";
import { hasBtnAuth } from "@/utils";
import Fahuo from "./fahuo.vue";
import { Message } from 'element-ui';
export default {
  mixins: [tableMixin],
  components: {
    vxe_table,
    Fahuo,
    evaluate,
    info
  },
  data() {
    return {
      options: {
        id: "eshs_table",
        apiFn: list,
        apiImport: importLight,
        import: true,
        importKeys: {},
        import: !true,
        columns: [
          {
            field: "id",
            title: "ID",
          },
          {
            field: "transactionType",
            title: "类型",
            type: "html",
            width: 100,
            formatter: ({ row }) => {
              if (row.transactionType == 0) {
                return "以旧换新";
              } else if (row.transactionType == 1) {
                return "以旧换旧";
              } else {
                return "现金回收";
              }
            },
          },
          {
            field: "recycleNum",
            title: "回收数量",
          },

          {
            field: "contact",
            title: "联系方式",
          },
          {
            field: "state",
            title: "状态",
            search: true,
            valueType: "select",
            options: [
              {
                label: "待评估",
                value: 0,
              },
              {
                label: "评估完成",
                value: 1,
              },

              {
                label: "客户已寄出",
                value: 2,
              },
              {
                label: "收到客户寄货",
                value: 3,
              },
              {
                label: "商家确认发货",
                value: 4,
              },
              {
                label: "客户确认收货/收款",
                value: 5,
              },
              {
                label: "完成",
                value: 9,
              },
              {
                label: "",
                value: -1,
              },
            ],
            type: "html",
            width: 150,
            formatter: ({ row }) => {
              if (row.state == -1) {
                return "<span style='color:red'>不适合回收</span>";
              } else {
                let arr = [
                  "待评估(评估后发货)",
                  "<span style='color:green'>评估完成(待收货)</span>",
                  "客户已寄出",
                  "收到客户寄货",
                  "平台已发货",
                  "客户确认收货/收款",
                  null,
                  null,
                  null,
                  "完成",
                ];
                return arr[row.state];
              }
            },
          },
          {
            field: "note",
            title: "补充说明",
          },
        ],
        btnWidth: 250,
        btn: [
          {
            title: "去评估",
            handleName: "handleEval",
            type: "primary",
            show:row=>row.state==0 && hasBtnAuth('menu_product_esProduct_eval')
          },
          {
            title: "发货",
            handleName: "handleSend",
            type: "primary",
            show:row=>row.state==3
          },
          {
            title: "确认收货",
            handleName: "handlerReceiveAck",
            type: "success",
            show:row=>row.state==2
          },
          {
            title: "详情",
            handleName: "handleDetail",
            type: "info",
          },
        ],
      },
    };
  },
  methods: {
    handleEval(row) {
      this.$refs.evaluateDialog.open(row,false);
    },
    handleDetail(row){
      this.$refs.info.open(row,true);
    },
    handleSend(row){
      this.$refs.Fahuo.open(row);
    },
    async handlerReceiveAck(row){
      const res = await receiveAck({
        id:row.id
      })
      if(!res.status){
        Message.success('收货成功')
        this.success()
      }
    }
  },
};
</script>
